package com.mf.all.utils.tree;

import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;
import org.apache.commons.lang3.ObjectUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: lmf
 * @Create: 2025/4/5 10:49
 * @module
 */
@Data
public abstract class AbstractTreeNode<T extends AbstractTreeNode<T, V, K>, V, K> implements TreeNode<T, V, K> {

    @Override
    public abstract V getId();

    @Override
    public abstract K getPid();

    public Integer sort;
    @TableField(exist = false)
    public List<T> children = new ArrayList<>();

    @Override
    public Integer getSort() {
        return this.sort;
    }

    public void setSort(Integer sort) {
        this.sort = sort;
    }

    @Override
    public List<T> getChildren() {
        return this.children;
    }

    @Override
    public void setChildren(List<T> children) {
        this.children = children;
    }

    @Override
    public void addChildren(T children) {
        if (ObjectUtils.isEmpty(this.children)) {
            this.children = new ArrayList<>();
        }
        this.children.add(children);
    }


}
